package com.java46.carera.department;

import com.java46.carera.base.entity.Department;
import com.java46.carera.base.entity.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
public class DepartmentController {
    @Autowired
    private DepartmentService departmentService;

    // 添加
    @RequestMapping("/addDepartment")
    public String addDepartment(String department_name, String department_introduction){
        departmentService.addDepartment(department_name, department_introduction);  // 获取页面上的值
        return "department/department";
    }

    // 删除
    @RequestMapping("/delDepartment")
    public String delDepartment(Integer department_id){
        departmentService.delDepartment(department_id);
        return "department/department";
    }

    // 修改前的查询
    @RequestMapping(value = "/selectDepartment",  produces = "application/json;charset=utf-8")
    @ResponseBody
    public JsonResult  modifyDepartment(Integer department_id){
        JsonResult jsonResult = departmentService.selectDepartment(department_id);
        return jsonResult;
    }

    // 修改
    @RequestMapping("/modifytDepartment")
    public String modifyDepartment(Integer department_id, String department_name, String department_introduction){
        departmentService.modifyDepartment(department_id, department_name, department_introduction);
        return "department/department";
    }

    // 查询所有
    @RequestMapping("/selectDepartmentAll")
    @ResponseBody
    public JsonResult selectDepartmentAll(Integer pagenNum, String depname){
        JsonResult jsonResult = departmentService.selectDepartmentAll(pagenNum, depname);
        return jsonResult;
    }

    // 查询，用于部门的下拉框
    @RequestMapping("/selectAllDep")
    @ResponseBody
    public JsonResult selectAllDep(){
        JsonResult jsonResult = departmentService.selectAllDep();
        return jsonResult;
    }

    // 用于员工，根据部门编号查询出该部门下拥有的职位
    public Department selectDepartmentStaff(Integer department_id){
        Department department = departmentService.selectDepartmentStaff(department_id);
        return department;
    }
}
